﻿using MediatR;
using MS.Data.API.Read.Command.User;
using MS.Data.Domain;
using MS.Data.ErrorCode;
using MS.Data.Infratructrue.Istanbul;

namespace MS.Data.API.Read.CommandHandle.User
{
    /// <summary>
    /// 循环显示角色命令处理
    /// </summary>
    public class GetRoleCommandHandel : IRequestHandler<GetRoleCommand, APIResult<List<Role>>>
    {
        IBaseRepository<Role> roleRep;

        public GetRoleCommandHandel(IBaseRepository<Role> roleRep)
        {
            this.roleRep = roleRep;
        }

        public Task<APIResult<List<Role>>> Handle(GetRoleCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<Role>> result = new APIResult<List<Role>>();
            result.code = APIEnum.显示成功;
            result.mes = APIEnum.显示成功.ToString();

            var list = roleRep.GetAll();

            result.data=list.ToList();
            return Task.FromResult(result);
        }
    }
}
